// OGoMojo
// Whitemice.MOGI.IRelation
// License: LGPL
// Copyright: Whitemice Consulting, 2006
// Author(s): Adam Tauno Williams (awilliam@whitemice.org)
using System;

namespace Whitemice.MOGI
{
	public class Relation : IRelation
	{
		protected ERelationType	type;
		protected string		source;
		protected string		target;
		protected string		label;
		protected string		comment;
		protected string		id;
		
		public Relation(ERelationType type, string source, string target, 
			string label, string comment)
		{
			Initialize(type, source, target, label, comment, null);
		}
		
		public Relation(ERelationType type, string source, string target, 
			string label, string comment, string id)
		{
			Initialize(type, source, target, label, comment, id);
		}
		
		protected void Initialize(ERelationType type, string source, string target, 
			string label, string comment, string id)
		{
			this.type = type;
			this.source = source;
			this.target = target;
			this.label = label;
			this.comment = comment;
			this.id = id;		
		}
		
		public string Name
		{
			get 
			{ 
				return "Relation/" +
					MOGI.DocumentTypeAsString(source) + "/" +
					MOGI.Id(source) + "/" +
					MOGI.RelationTypeAsString(type) + "/" +
					MOGI.DocumentTypeAsString(target) + "/" +
					MOGI.Id(target);
			}
		}
		
		public ERelationType Type 
		{ 
			get { return type; }
			set { type = value; }
		}
		
		public string Source 
		{
			get { return source; }
			set { source = value; }
		}
		
		public string Target 
		{ 
			get { return target; }
			set { target = value; }
		}
		
		
		public string	Label 
		{ 
			get
			{
				if (label == null)
					return "";
				return label; 
			}
			set { label = value; }
		}
		
		/// \brief Access the comment on the relation
		/// \warn Not all relations support storig a comment
		public string Comment 
		{ 
			get 
			{ 
				if (label == null)
					return "";
				return comment; 
			}
			set { comment = value; }
		}
		
		/// \brief Retrieve description of relation
		/// \todo Implement
		public string Description 
		{ 
			get { return ""; }
		}
		
		/// \brief Access the backend's id for the relation
		/// \warn Only backends should use this value, NOT APPLICATIONS
		/// \todo Is there a protection level, like internal, more appropriate?
		public string InternalId
		{
			get { return id; }
			set { id = value; }
		}
	}
}